<!-- 注册 -->
<template>
  <div class="register-container">
    <van-form @submit="onRegisterSubmit"
              class="login-form-style">
      <van-cell-group inset>
        <van-field v-model="formData.username"
                   name="username"
                   label="用户名"
                   placeholder="用户名"
                   :rules="[{ required: true, message: '用户名' }]" />
        <van-field v-model="formData.phone"
                   name="phoneNum"
                   label="手机号"
                   placeholder="手机号"
                   :rules="[{ required: true, message: '手机号' }]" />
        <van-field v-model="formData.email"
                   name="email"
                   label="邮箱"
                   placeholder="邮箱"
                   :rules="[{ required: true, message: '邮箱' }]" />
        <van-field v-model="formData.password"
                   type="password"
                   name="password"
                   label="密码"
                   placeholder="密码"
                   :rules="[{ required: true, message: '请填写密码' }]" />
        <van-field v-model="formData.confimPassword"
                   type="password"
                   name="confimPassword"
                   label="确认密码"
                   placeholder="确认密码"
                   :rules="[{ required: true, message: '请再次填写密码' }]" />
      </van-cell-group>
      <div class="btn-div-style">
        <van-button class="login-form-btn-style"
                    round
                    block
                    type="primary"
                    native-type="submit">
          注册
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { Toast } from "vant";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data () {
    //这里存放数据
    return {
      formData: {
        username: "",
        phone: "",
        email: "",
        password: "",
        confimPassword: "",
      },
      list: [],
    };
  },
  //方法集合
  methods: {
    onRegisterSubmit (values) {
      // 格式校验
      // if (values.password !== values.confimPassword) {

      // }
      var queryData = {
        ...this.formData,
      };
      var header = {
        "Content-Type": "application/json;charset=UTF-8",
      };
      this.$http
        .post_json(this.$reqPrefix.user + "/im/users/register", queryData, header)
        .then((res) => {
          console.log(res);
          Toast.success("注册成功");
          this.$router.push("/public/login");
        })
        .catch((error) => {
          Toast.error(error.data.message);
        });
      console.log("submit", values);
    },
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created () { },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted () { },
  //生命周期 - 创建之前
  beforeCreate () { },
  //生命周期 - 挂载之前
  beforeMount () { },
  //生命周期 - 更新之前
  beforeUpdate () { },
  //生命周期 - 更新之后
  updated () { },
  //生命周期 - 销毁之前
  beforeUnmount () { },
  //生命周期 - 销毁完成
  unmounted () { },
  //如果页面有keep-alive缓存功能，这个函数会触发
  activated () { },
};
</script>
<style lang="less" scoped>
//@import url(); 引入公共css类
.register-container {
  position: absolute;
  height: 100%;
  width: 100%;
  background: whitesmoke;
}
.login-form-style {
  margin: 0.6rem;
}
.btn-div-style {
  display: flex;
  justify-content: center;
  .login-form-btn-style {
    width: 8rem;
    margin-top: 1rem;
  }
}
</style>
